home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Burning & Media / GB-PVR 1.2.13 / GBPVR10213.msi / Cabs.w1.cab / CSSProgrammeTableLoad.cs33 < prev    next >
Text File  |  2008-04-09  |  47KB  |  884 lines

  1. using System;
  2. using System.Collections;
  3. using System.IO;
  4. using System.Web;
  5. using System.Web.Caching;
  6. using System.Web.UI.WebControls;
  7. using GBPVR.Public;
  8. using GBPVRSchedule;
  9.  
  10. /// <summary>
  11. /// Summary description for CSSProgrammeTableLoad
  12. /// </summary>
  13. /// 
  14. namespace gbweb.classes
  15. {
  16.     public class CSSProgrammeTableLoad
  17.     {
  18.         private Channel channel;
  19.         private string displayClass;
  20.  
  21.         private bool searchRecordings = false;
  22.  
  23.         private Cache pageCache = new Cache();
  24.  
  25.         private Type pageType;
  26.  
  27.         private HttpCookie cookie;
  28.  
  29.         private string forcedScrollbar = string.Empty;
  30.         private string CONTENTS = string.Empty;
  31.  
  32.         //Create the table arrays to hold any found programs functional information
  33.         private ArrayList Status = new ArrayList();
  34.         private ArrayList AirDate = new ArrayList();
  35.         private ArrayList Channel = new ArrayList();
  36.         private ArrayList Description = new ArrayList();
  37.  
  38.         //Create the table arrays to hold any found programs display formatting information
  39.         private ArrayList divStatusArray = new ArrayList();
  40.         private ArrayList divAirDateArray = new ArrayList();
  41.         private ArrayList divChannelArray = new ArrayList();
  42.         private ArrayList divDescArray = new ArrayList();
  43.         
  44.         public CSSProgrammeTableLoad()
  45.         {
  46.         }
  47.  
  48.         public string getForcedScrollBar()
  49.         {
  50.             return forcedScrollbar;
  51.         }
  52.  
  53.         public string getContents()
  54.         {
  55.             return CONTENTS;
  56.         }
  57.  
  58.         public void Dispose()
  59.         {
  60.             Status.Clear();
  61.             AirDate.Clear();
  62.             Channel.Clear();
  63.             Description.Clear();
  64.             divStatusArray.Clear();
  65.             divAirDateArray.Clear();
  66.             divChannelArray.Clear();
  67.             divDescArray.Clear();
  68.         }
  69.  
  70.         public ArrayList sortDisplay(ArrayList sortOrders, ArrayList programmesToSort, bool isSortingSchedule)
  71.         {
  72.             programmesToSort.Sort(new programmeComparer(sortOrders, isSortingSchedule));
  73.  
  74.             return programmesToSort;
  75.         }
  76.  
  77.         #region Page Load code for the TableView - ProcessTable
  78.         //This is the main driver routine for loading the TableView
  79.         public void processTable(Type pagetype, ArrayList sortOrders, Cache cache, HttpRequest Request, HttpServerUtility Server, ProgrammeDisplay2 displayProgramme, bool strmAllowed, Programme programme, ScheduledRecording scheduledRecording, bool finalize_table)
  80.         {
  81.             pageCache = cache;
  82.             pageType = pagetype;
  83.             Schedule scheduleHelper = Global.Schedule;
  84.             if (!finalize_table)
  85.             {
  86.                 //Default the quality string
  87.                 String quality = string.Empty;
  88.  
  89.                 if (scheduledRecording != null)
  90.                 {
  91.                     //Set the quailit string to the appropriate value
  92.                     switch (scheduledRecording.getQualitySetting())
  93.                     {
  94.                         case (int) Schedule.Quality.Low:
  95.                             quality = "Low";
  96.                             break;
  97.                         case (int) Schedule.Quality.Medium:
  98.                             quality = "Medium";
  99.                             break;
  100.                         case (int) Schedule.Quality.High:
  101.                             quality = "High";
  102.                             break;
  103.                         case (int) Schedule.Quality.Custom1:
  104.                             quality = "Custom 1";
  105.                             break;
  106.                         case (int) Schedule.Quality.Custom2:
  107.                             quality = "Custom 2";
  108.                             break;
  109.                         case (int) Schedule.Quality.LiveTV:
  110.                             quality = "LiveTV";
  111.                             break;
  112.                         default:
  113.                             quality = string.Empty;
  114.                             break;
  115.                     }
  116.                 }
  117.  
  118.  
  119.                 //Set the channel that is associated to this schedule
  120.                 if (scheduledRecording != null)
  121.                 {
  122.                     channel = scheduleHelper.GetChannelByOID(scheduledRecording.getChannelOID());
  123.                 }
  124.                 else
  125.                 {
  126.                     channel = scheduleHelper.GetChannelByOID(programme.getChannelOID());
  127.                 }
  128.  
  129.                 //Description Load Routine.  We use a table cell since it matched the old code and provides a convienent container for storing not
  130.                 //only the formated display but also the appropriate css class for the status of the programme.  The formatted description is then added to the
  131.                 //Description array.
  132.                 displayClass = string.Empty;
  133.                 TableCell programmeCell = new TableCell();
  134.                 displayProgramme.FillProgrammeDisplay(Server, programmeCell, programme, scheduledRecording, true);
  135.                 Description.Add(programmeCell.Text);
  136.                 displayClass = programmeCell.CssClass;
  137.  
  138.                 //Status Load Routine.  Set the appropirate value for the status of the schedule and then add it to the Status array.
  139.                 string status = string.Empty;
  140.  
  141.                 string checkMe = "$";
  142.                 if (pageType.Name == "Manage2")
  143.                 {
  144.                     if (scheduledRecording != null)
  145.                     {
  146.                         checkMe = "<input name=\"item" + scheduledRecording.getOID() + "\" type=\"checkbox\" value=\"" +
  147.                                   scheduledRecording.getOID() + "\"> Delete Me$";
  148.                     }
  149.                 }
  150.  
  151.                 if (scheduledRecording != null)
  152.                 {
  153.                     switch (scheduledRecording.getRecordingStatus())
  154.                     {
  155.                         case ScheduledRecording.STATUS_PENDING:
  156.                             //Pending status entries will always have 4 dimensions
  157.                             status = "pending$" + checkMe + quality + "$" + "\"" + pageType.Name + ".aspx?cancel=" + scheduledRecording.getOID() +
  158.                                      "\"" + "$" + displayClass;
  159.                             Status.Add(status);
  160.                             break;
  161.                         case ScheduledRecording.STATUS_IN_PROGRESS:
  162.                             //In-Progress status entries will always have between 5 and 7 dimensions
  163.                             status = "in-progress$" + checkMe + quality + "$\"" +
  164.                                      Download.GetDownloadUrl(false, false, scheduledRecording.getOID()) + "\"$\"" +
  165.                                      Download.GetDownloadUrl(true, true, scheduledRecording.getOID()) + "\"";
  166.                             if (strmAllowed)
  167.                             {
  168.                                 status += "$" + "\"public/Player2.aspx?rid=" + scheduledRecording.getOID() + "&type=mr" +
  169.                                           "\" onclick=\"EditPop5(this.href,'Add1');return false;\"";
  170.                             }
  171.                             if (programme == null)
  172.                             {
  173.                                 status += "$" + "\"" + pageType.Name + ".aspx?cancel=" + scheduledRecording.getOID() + "\"";
  174.                             }
  175.                             status += "$" + displayClass;
  176.                             Status.Add(status);
  177.                             break;
  178.                         case ScheduledRecording.STATUS_COMPLETED:
  179.                             //Available status entries will always have between 5 and 7 dimensions
  180.                             status = "available$" + checkMe + quality + "$\"" +
  181.                                      Download.GetDownloadUrl(false, false, scheduledRecording.getOID()) + "\"$\"" +
  182.                                      Download.GetDownloadUrl(true, true, scheduledRecording.getOID()) + "\"";
  183.                             if (strmAllowed)
  184.                             {
  185.                                 status += "$" + "\"public/Player2.aspx?rid=" + scheduledRecording.getOID() + "&type=mr" +
  186.                                           "\" onclick=\"EditPop5(this.href,'Add1');return false;\"";
  187.                             }
  188.                             if (programme == null)
  189.                             {
  190.                                 status += "$" + "\"" + pageType.Name + ".aspx?cancel=" + scheduledRecording.getOID() + "\"";
  191.                             }
  192.                             status += "$" + displayClass;
  193.                             Status.Add(status);
  194.                             break;
  195.                         case ScheduledRecording.STATUS_COMPLETED_WITH_ERROR:
  196.                             //Completed with error status entries will always have 4 dimensions
  197.                             status = "completed-error$" + checkMe + quality + "$" + "\"" + pageType.Name + ".aspx?cancel=" +
  198.                                      scheduledRecording.getOID() + "\"" + "$" + displayClass;
  199.                             Status.Add(status);
  200.                             break;
  201.                         case ScheduledRecording.STATUS_CONFLICT:
  202.                             //Conflict status entries will always have 4 dimensions
  203.                             status = "conflict$" + checkMe + quality + "$" + "\"" + pageType.Name + ".aspx?cancel=" + scheduledRecording.getOID() +
  204.                                      "\"" + "$" + displayClass;
  205.                             Status.Add(status);
  206.                             break;
  207.                         case ScheduledRecording.STATUS_PLACE_HOLDER:
  208.                             //Reocurring status entries will always have 4 dimensions
  209.                             status = "reocurring$" + checkMe + quality + "$" + "\"" + pageType.Name + ".aspx?cancel=" +
  210.                                      scheduledRecording.getOID() +
  211.                                      "\"" + "$listingReocurring";
  212.                             Status.Add(status);
  213.                             break;
  214.                         case ScheduledRecording.STATUS_DELETED:
  215.                             //Deleted status entries will always have 2 dimensions
  216.                             status = "deleted" + "$listingDeleted";
  217.                             Status.Add(status);
  218.                             break;
  219.                         default:
  220.                             //Unknown status entries will always have 2 dimensions
  221.                             status = "unknown" + "$" + displayClass;
  222.                             Status.Add(status);
  223.                             break;
  224.                     }
  225.                 }
  226.                 //The program is not currently recorded so we want to give the user the option to record this programme
  227.                 else
  228.                 {
  229.                     //if (pageType.Name == "SearchResults2")
  230.                     //{
  231.                         searchRecordings = true;
  232.                         status = "open" + "$" + 
  233.                                  "<input name=\"item" + programme.getOID() + "\" type=\"checkbox\" value=\"" + programme.getOID() + "\"> Record Me$" + displayClass;
  234.                     //}
  235.                     //else
  236.                     //{
  237.                     //    status = "<input name=\"item" + scheduledRecording.getOID() + "\" type=\"checkbox\" value=\"" +
  238.                     //              scheduledRecording.getOID() + "\"> Delete Me$"; 
  239.                     //}
  240.                     Status.Add(status);  
  241.                 }
  242.                 //AirDate Load Routine.  The date is pulled from the schedule and formatted appropriatly.  It is then loaded to the AirDate array.
  243.                 string date = null;
  244.                 string time = null;
  245.                 string airdate = string.Empty;
  246.                 string days = string.Empty;
  247.                 if (scheduledRecording != null)
  248.                 {
  249.                     switch (scheduledRecording.getRecordingType())
  250.                     {
  251.                         case ScheduledRecording.TYPE_RECORD_ONCE:
  252.                             date = scheduledRecording.getStartTime().ToLongDateString();
  253.                             time = scheduledRecording.getStartTime().ToShortTimeString() + " - " +
  254.                                    scheduledRecording.getEndTime().ToShortTimeString();
  255.                             break;
  256.                         case ScheduledRecording.TYPE_RECORD_DAILY:
  257.                             date = "Daily";
  258.                             time = scheduledRecording.getStartTime().ToShortTimeString() + " - " +
  259.                                    scheduledRecording.getEndTime().ToShortTimeString();
  260.                             break;
  261.                         case ScheduledRecording.TYPE_RECORD_WEEK_DAYS:
  262.                             date = "Week Days";
  263.                             time = scheduledRecording.getStartTime().ToShortTimeString() + " - " +
  264.                                    scheduledRecording.getEndTime().ToShortTimeString();
  265.                             break;
  266.                         case ScheduledRecording.TYPE_RECORD_WEEKEND_DAYS:
  267.                             date = "Weekend Days";
  268.                             time = scheduledRecording.getStartTime().ToShortTimeString() + " - " +
  269.                                    scheduledRecording.getEndTime().ToShortTimeString();
  270.                             break;
  271.                         case ScheduledRecording.TYPE_RECORD_WEEKLY:
  272.                             date = "Weekly: " + scheduledRecording.getStartTime().DayOfWeek;
  273.                             time = scheduledRecording.getStartTime().ToShortTimeString() + " - " +
  274.                                    scheduledRecording.getEndTime().ToShortTimeString();
  275.                             break;
  276.                         case ScheduledRecording.TYPE_RECORD_SEASON:
  277.                             date = "Season";
  278.                             if (scheduledRecording.getStartTime().Year != 2001)
  279.                                 time = scheduledRecording.getStartTime().ToShortTimeString() + " - " +
  280.                                        scheduledRecording.getEndTime().ToShortTimeString();
  281.                             {
  282.                                 days = scheduleHelper.getSeasonDayString(scheduledRecording);
  283.                             }
  284.                             break;
  285.                     }
  286.                 }
  287.                 else
  288.                 {
  289.                     date = programme.getStartTime().ToLongDateString();
  290.                     time = programme.getStartTime().ToShortTimeString() + " - " +
  291.                             programme.getEndTime().ToShortTimeString();
  292.                 }
  293.                 airdate = "<div class=\"airDate\">" + date + "</div><br><div class=\"airTime\">" + time + "</div>";
  294.                 if (days != string.Empty)
  295.                 {
  296.                     airdate += "<br><div class=\"airTime\">" + days + "</div>";
  297.                 }
  298.                 AirDate.Add(airdate);
  299.  
  300.                 //Channel Load Routine.  Pull the channel, channel name and channel icon and format appropriatly.  The result is then added to the Channel array.
  301.                 string channelname = string.Empty;
  302.  
  303.                 if (channel != null)
  304.                 {
  305.                     string channelName = channel.getName();
  306.                     if (channelName.StartsWith(channel.getChannelNumber().ToString()))
  307.                         // cosmetic stuff for my american friends
  308.                     {
  309.                         if (channelName != channel.getChannelNumber().ToString())
  310.                         {
  311.                             channelName = channelName.Substring(channel.getChannelNumber().ToString().Length + 1);
  312.                         }
  313.                         else
  314.                         {
  315.                             channelName = "";
  316.                         }
  317.                     }
  318.  
  319.                     cookie = Request.Cookies["useChannelIcons"];
  320.                     string UseChannelIcons = cookie != null ? cookie.Value : "chnlText";
  321.  
  322.                     if (UseChannelIcons != "chnlIcon")
  323.                     {
  324.                         channelname = "<div class=\"channelNum\">" + channel.getChannelNumber() +
  325.                                       "</div><div class=\"channelName\">" + channelName;
  326.                     }
  327.                     else
  328.                     {
  329.                         channelname = "<div class=\"channelNum\"></div><div class=\"channelName\">";
  330.                     }
  331.  
  332.                     string channelIcon =
  333.                         GetChannelIcon(channel.getChannelNumber(), new string[] {channel.getName(), channelName});
  334.                     if (channelIcon != null && (UseChannelIcons != "chnlText"))
  335.                     {
  336.                         channelname += "<div id=\"CHANNEL_ICON\"><img src=\"" +
  337.                                        Download.GetDownloadUrl(false, true, Download.InternalFiles.ChannelIcon,
  338.                                                                Server.UrlEncode(channelIcon)) +
  339.                                        "\" alt=\"\" width=\"67\" height=\"50\" hspace=\"0\" vspace=\"0\" border=\"1\" runat=\"server\"></div></div>";
  340.                     }
  341.                     else
  342.                     {
  343.                         channelname += "</div>";
  344.                     }
  345.                     Channel.Add(channelname);
  346.                 }
  347.                 else
  348.                 {
  349.                     channelname = "" + "<br>" + "";
  350.                     Channel.Add(channelname);
  351.                 }
  352.             }
  353.  
  354.             if (finalize_table)
  355.             {
  356.                 //Set the value for the header fields that shows what the current sort column is and in what order it is sorted              
  357.                 string hdrStatus = "<div class=\"headerRow\" style=\"width:15%\"><a href=\"" + pageType.Name + ".aspx?sort=status\"><span>Status</span></a>" + getSortDescription(sortOrders[0], "status") + "</div>";
  358.                 string hdrStatus2 = "<div class=\"headerRow\" style=\"width:5%\"><input type=\"checkbox\" class=\"selectAll\" onclick=\"SelectAllCheckboxes(this);\"><span>All</span></div><div class=\"headerRow\" style=\"margin-left: 5%;width:10%\"><a href=\"" + pageType.Name + ".aspx?sort=status\"><span>Status</span></a>" + getSortDescription(sortOrders[0], "status") + "</div>";
  359.                 string hdrAirDate = "<div class=\"headerRow\" style=\"margin-left: 15%; width:15%\"><a href=\"" + pageType.Name + ".aspx?sort=datetime\"><span>Air Date</span></a>" + getSortDescription(sortOrders[0], "datetime") + "</div>\n";
  360.                 string hdrChannel = "<div class=\"headerRow\" style=\"margin-left: 30%; width:10%\"><a href=\"" + pageType.Name + ".aspx?sort=channel\">Channel</a>" + getSortDescription(sortOrders[0], "channel") + "</div>\n";
  361.                 string hdrDesc = "<div class=\"headerRow\" style=\"margin-left: 40%; width:60%\"><a href=\"" + pageType.Name + ".aspx?sort=title\">Show</a>" + getSortDescription(sortOrders[0], "title") + "</div>\n";
  362.                 
  363.                 //Div Load Routine.  These calls take the functional results that are stored in the arrays and then load them to a new array that includes the 
  364.                 //formatting for displaying on the page.  After each call we remove the data stored in the functional array so we are not being a memory hog.
  365.                 if (searchRecordings)
  366.                 {
  367.                     fillDiv(Status, hdrStatus2, "status");
  368.                 }
  369.                 else
  370.                 {
  371.                     fillDiv(Status, hdrStatus2, "status");
  372.                 }
  373.                 Status.Clear();
  374.                 fillDiv(AirDate, hdrAirDate, "airdate");
  375.                 AirDate.Clear();
  376.                 fillDiv(Channel, hdrChannel, "channel");
  377.                 Channel.Clear();
  378.                 fillDiv(Description, hdrDesc, "desc");
  379.                 Description.Clear();
  380.  
  381.                 //Set the first time indicator to true so that we know that we are loading the header row and not detail rows.
  382.                 bool first_time = true;
  383.  
  384.                 //Since all the arrays will have the same number of entries we can just use one of them as the itterator.  We proccess each entry in the formatted
  385.                 //arrays and add the final row level formating for each entry.
  386.                 while (divStatusArray.Count > 0)
  387.                 {
  388.                     //Pull each entry from the formatted array.
  389.                     string status = (string) divStatusArray[0];
  390.                     string airdate = (string) divAirDateArray[0];
  391.                     string channelinfo = (string) divChannelArray[0];
  392.                     string desc = (string) divDescArray[0];
  393.                     //Since we know have the current array entry as a string we can remove it from memory to help reduce resources being used
  394.                     divStatusArray.Remove(status);
  395.                     divAirDateArray.Remove(airdate);
  396.                     divChannelArray.Remove(channelinfo);
  397.                     divDescArray.Remove(desc);
  398.                     //Check to see if this is the first time in the loop.  If it is then we know we are working with the header row and set the line formatting accordingly.
  399.                     if (first_time)
  400.                     {
  401.                         forcedScrollbar += status + airdate + channelinfo + desc + "<br><br>";
  402.                         first_time = false;
  403.                     }
  404.                         //If it is not the first time then we know we are on the detial lines.  So we combine the seperate entries into one line and add the appropriate line formatting.
  405.                     else
  406.                     {
  407.                         CONTENTS += "<div class=\"listingRow\">\n";
  408.                         CONTENTS += "<div class=\"listings\" style=\"width:15%\">\n" + status + "</div>\n" +
  409.                                               "<div class=\"listings\" style=\"margin-left: 15%; width:15%\">\n" +
  410.                                               airdate + "</div>\n" +
  411.                                               "<div class=\"listings\" style=\"margin-left: 30%; width:10%\">\n" +
  412.                                               channelinfo + "</div>\n" +
  413.                                               "<div class=\"listings\" style=\"margin-left: 40%; width:60%\">\n" + desc +
  414.                                               "</div>\n</div>\n";
  415.                     }
  416.                 }
  417.             }
  418.         }
  419.  
  420.         //This routine pulls the data from an array loaded with the formatted functional information and applys the appropriate grouping formatting.
  421.         private void fillDiv(ArrayList info, string hdr, string arraytype)
  422.         {
  423.             //Load the first item in the array with the header information
  424.             switch (arraytype)
  425.             {
  426.                 case "status":
  427.                     {
  428.                         divStatusArray.Add(hdr);
  429.                     }
  430.                     break;
  431.                 case "airdate":
  432.                     {
  433.                         divAirDateArray.Add(hdr);
  434.                     }
  435.                     break;
  436.                 case "channel":
  437.                     {
  438.                         divChannelArray.Add(hdr);
  439.                     }
  440.                     break;
  441.                 case "desc":
  442.                     {
  443.                         divDescArray.Add(hdr);
  444.                     }
  445.                     break;
  446.             }
  447.  
  448.             //Iterate through the array that contains the formatted functional information
  449.             while (info.Count > 0)
  450.             {
  451.                 //Pull the current array item out and assign it to a string for processing
  452.                 string item = (string)info[0];
  453.                 //Some of the array entries (depending on type of array being processed) may conatain and array of values.  We need to seperate them out so that we
  454.                 //have individual units to work with.
  455.                 string[] items = item.Split(new char[] { '$' }, 7);
  456.                 //Now that we have the current array entry in a string we can remove the entry from the array to reduce resource usage.
  457.                 info.Remove(item);
  458.                 //Initialice a string value that is used to simplify the concatenation of status infromation for the recording.
  459.                 string single = string.Empty;
  460.                 //Process the current array item (now in the string object called item) based on what type of recording status was passed into the method
  461.                 switch (arraytype)
  462.                 {
  463.                     case "status":
  464.                         //Format the status portion of the display row with the current item being processed.
  465.                         //Since we are processing a status array we know we are dealing with an array entry that contained seperate entries and thus was
  466.                         //split into a new array object called items.  Each item in items contains a piece of information for formatting the status area of the
  467.                         //display line.
  468.                         switch (items[0])
  469.                         {
  470.                             case "pending":
  471.                                 single = "<div class=\"" + items[items.Length - 1] + "\">Pending</div>\n" + items[1] + " <div class=\"quality\" title=\"Quality\">Quality: " + items[2] + "</div><br/>\n<div class=\"butCancel\" title=\"Cancel\"><a href=\"\" onclick=\"goCancel(" + items[3].Replace("\"", "'") + ");return false;\" class=\"cellItem\">Cancel</div></a>";
  472.                                 break;
  473.                             case "in-progress":
  474.                                 single = "<div class=\"" + items[items.Length - 1] + "\">In-Progress</div>\n" + items[1] + " <div class=\"quality\" title=\"Quality\">Quality: " + items[2] + "</div><br/>\n<div class=\"butPlay\" title=\"Play\"><a href=" + items[3] + "class=\"cellItem\">Play</div></a>";
  475.                                 single += "<div class=\"butDownload\" title=\"Download\"><a href=" + items[4] + ">Download</div></a>\n";
  476.                                 if (items.Length == 8)
  477.                                 {
  478.                                     single += "<div class=\"butStream\" title=\"Stream\"><a href=" + items[5] + ">Stream</div></a>";
  479.                                     single += "<div class=\"butCancel\" title=\"Cancle\"><a href=" + items[6] + ">Cancel</div></a>";
  480.                                 }
  481.                                 else if (items.Length == 7)
  482.                                 {
  483.                                     single += "<div class=\"butStream\" title=\"Stream\"><a href=" + items[5] + ">Stream</div></a>";
  484.                                 }
  485.                                 break;
  486.                             case "available":
  487.                                 single = "<div class=\"" + items[items.Length - 1] + "\">Available</div>\n" + items[1] + " <div class=\"quality\" title=\"Quality\">Quality: " + items[2] + "</div><br/>\n<div class=\"butPlay\" title=\"Play\"><a href=" + items[3] + "class=\"cellItem\">Play</div></a>";
  488.                                 single += "<div class=\"butDownload\" title=\"Download\"><a href=" + items[4] + ">Download</div></a>\n";
  489.                                 if (items.Length == 8)
  490.                                 {
  491.                                     single += "<div class=\"butStream\" title=\"Stream\"><a href=" + items[5] + ">Stream</div></a>";
  492.                                     single += "<div class=\"butCancel\" title=\"Cancle\"><a href=" + items[6] + ">Cancel</div></a>";
  493.                                 }
  494.                                 else if (items.Length == 7)
  495.                                 {
  496.                                     single += "<div class=\"butStream\" title=\"Stream\"><a href=" + items[5] + ">Stream</div></a>";
  497.                                 }
  498.                                 break;
  499.                             case "completed-error":
  500.                                 single = "<div class=\"" + items[items.Length - 1] + "\">Failed</div>\n" + items[1] + " <div class=\"quality\" title=\"Quality\">Quality: " + items[2] + "</div><br/>\n<div class=\"butCancel\" title=\"Cancel\"><a href=\"\" onclick=\"goCancel(" + items[3].Replace("\"", "'") + ");return false;\" class=\"cellItem\"><span>Cancel</sapn></div></a>";
  501.                                 break;
  502.                             case "conflict":
  503.                                 single = "<div class=\"" + items[items.Length - 1] + "\">Conflict</div>\n" + items[1] + " <div class=\"quality\" title=\"Quality\">Quality: " + items[2] + "</div><br/>\n<div class=\"butCancel\" title=\"Cancel\"><a href=\"\" onclick=\"goCancel(" + items[3].Replace("\"", "'") + ");return false;\" class=\"cellItem\"><span>Cancel</span></div></a>";
  504.                                 break;
  505.                             case "reocurring":
  506.                                 single = "<div class=\"" + items[items.Length - 1] + "\">Reocurring</div>\n" + items[1] + " <div class=\"quality\" title=\"Quality\">Quality: " + items[2] + "</div><br/>\n<div class=\"butCancel\" title=\"Cancel\"><a href=\"\" onclick=\"goCancel(" + items[3].Replace("\"", "'") + ");return false;\" class=\"cellItem\"><span>Cancel</span></div></a>";
  507.                                 break;
  508.                             case "deleted":
  509.                                 single = "<div class=\"" + items[items.Length - 1] + "\">Deleted</div>";
  510.                                 break;
  511.                             case "unkown":
  512.                                 single = "<div class=\"" + items[items.Length - 1] + "\">Unkown</div>";
  513.                                 break;
  514.                             case "open":
  515.                                 single = "<div class=\"" + items[items.Length - 1] + "\">" + items[1] + "</div>";
  516.                                 break;
  517.                         }
  518.                         divStatusArray.Add(single);
  519.                         break;
  520.                     case "airdate":
  521.                         //Format the airdate portion of the display row with the current item being processed.
  522.                         {
  523.                             divAirDateArray.Add("<div class=\"cellItem\">" + item + "</div><br/><br/>");
  524.                         }
  525.                         break;
  526.                     case "channel":
  527.                         //Format the channel portion of the display row with the current item being processed.
  528.                         {
  529.                             divChannelArray.Add("<div class=\"cellItem\">" + item + "</div>");
  530.                         }
  531.                         break;
  532.                     case "desc":
  533.                         //Format the description portion of the display row with the current item being processed.
  534.                         {
  535.                             divDescArray.Add("<div class=\"cellItem\">" + item + "</div>");
  536.                         }
  537.                         break;
  538.                 }
  539.             }
  540.         }
  541.         
  542.         #endregion
  543.  
  544.         #region Sorting processing logic
  545.  
  546.         //This checks the sort setting and if found it reverses the order from what it was set to
  547.         static string getSortDescription(object selectedSort, string thisSort)
  548.         {
  549.             if (selectedSort.ToString() == thisSort)
  550.                 return " (asc)";
  551.             else if (selectedSort.ToString() == thisSort + " desc")
  552.                 return " (desc)";
  553.             else
  554.                 return string.Empty;
  555.         }
  556.         #endregion
  557.  
  558.         #region Channel Icon procssing logic
  559.         private static string channelIconPath;
  560.         private static string[] channelIconExtensions;
  561.  
  562.         public string GetChannelIcon(int channelNumber, string[] channelNames)
  563.         {
  564.             // Get the Channel Icon Directory
  565.             if (channelIconPath == null)
  566.             {
  567.                 lock (pageType)
  568.                 {
  569.                     if (channelIconPath == null)
  570.                     {
  571.                         channelIconPath = Path.Combine(Global.Settings.GetInstallDir(), @"media\ChannelLogos");
  572.                         channelIconExtensions = Global.Settings.channelIconExtensions.Split(',');
  573.                     }
  574.                 }
  575.             }
  576.  
  577.             Hashtable channelIconCache = (Hashtable)pageCache["channelIconCache"];
  578.             if (channelIconCache == null)
  579.             {
  580.                 lock (pageType)
  581.                 {
  582.                     channelIconCache = (Hashtable)pageCache["channelIconCache"];
  583.                     if (channelIconCache == null)
  584.                     {
  585.                         channelIconCache = new Hashtable();
  586.                         pageCache.Add(
  587.                             "channelIconCache",
  588.                             channelIconCache,
  589.                             new CacheDependency(channelIconPath),
  590.                             DateTime.MaxValue,
  591.                             Cache.NoSlidingExpiration,
  592.                             CacheItemPriority.Normal,
  593.                             null);
  594.                     }
  595.                 }
  596.             }
  597.  
  598.             if (channelIconCache.ContainsKey(channelNumber))
  599.             {
  600.                 return (string)channelIconCache[channelNumber];
  601.             }
  602.  
  603.             lock (channelIconCache)
  604.             {
  605.                 if (channelIconCache.ContainsKey(channelNumber))
  606.                 {
  607.                     return (string)channelIconCache[channelNumber];
  608.                 }
  609.  
  610.                 string channelIconFile = null;
  611.                 foreach (string channelName in channelNames)
  612.                 {
  613.                     foreach (string channelIconExtension in channelIconExtensions)
  614.                     {
  615.                         string cleanName = channelName;
  616.                         string channelNameWork = channelName;
  617.                         while (cleanName.Contains("/"))
  618.                         {
  619.                             if (channelNameWork.Contains("/"))
  620.                             {
  621.                                 cleanName = channelNameWork.Remove(channelNameWork.IndexOf("/"), 1);
  622.                                 channelNameWork = cleanName;
  623.                             }
  624.                         }
  625.                         string probeFile = cleanName + "." + channelIconExtension;
  626.                         if (File.Exists(Path.Combine(channelIconPath, probeFile)))
  627.                         {
  628.                             channelIconFile = probeFile;
  629.                             break;
  630.                         }
  631.                     }
  632.                     if (channelIconFile != null) break;
  633.                 }
  634.                 channelIconCache[channelNumber] = channelIconFile;
  635.                 return channelIconFile;
  636.             }
  637.         }
  638.         #endregion
  639.  
  640.         #region Sorting processing logic
  641.  
  642.         class programmeComparer : IComparer
  643.         {
  644.  
  645.             IList sortKeys;
  646.             private IDictionary knownRecordings;
  647.             private bool isSortingSchedule;
  648.  
  649.             public programmeComparer(IList SortKeys, bool sortType)
  650.             {
  651.                 sortKeys = SortKeys;
  652.                 isSortingSchedule = sortType;
  653.  
  654.                 // build up a list of the recording we already know about
  655.                 Schedule scheduleHelper = Global.Schedule;
  656.                 knownRecordings = scheduleHelper.LoadKnownRecordings();
  657.             }
  658.  
  659.             #region IComparer Members
  660.  
  661.             public int Compare(object x, object y)
  662.             {
  663.                 for (int i = 0; i < sortKeys.Count; i++)
  664.                 {
  665.                     string key = sortKeys[i].ToString();
  666.                     int order = 1;
  667.                     if (key.EndsWith(" desc"))
  668.                     {
  669.                         key = key.Substring(0, key.Length - 5);
  670.                         order = -1;
  671.                     }
  672.                     int result = getRecordingValue(x, key).CompareTo(getRecordingValue(y, key));
  673.                     if (result != 0) return result * order;
  674.                 }
  675.                 return 0;
  676.             }
  677.  
  678.             #endregion
  679.  
  680.             IComparable getRecordingValue(object obj, string key)
  681.             {
  682.                 //Default the two types of objects that we could be dealing with for this sort
  683.                 ScheduledRecording scheduledRecording = new ScheduledRecording();
  684.                 Schedule scheduleHelper = Global.Schedule;
  685.                 Programme pgm = new Programme();
  686.                 if (isSortingSchedule)
  687.                 {
  688.                     scheduledRecording = (ScheduledRecording)obj;
  689.                 }
  690.                 else
  691.                 {
  692.                     pgm = (Programme)obj; 
  693.                 }
  694.  
  695.                 //Process the sorting for the appropriate object type
  696.                 if (!isSortingSchedule)
  697.                 {
  698.                     switch (key)
  699.                     {
  700.                         case "status":
  701.                             {
  702.                                 scheduledRecording = null;
  703.                                 if (knownRecordings.Contains(pgm.getOID()))
  704.                                     scheduledRecording = (ScheduledRecording)knownRecordings[pgm.getOID()];
  705.                                 if (scheduledRecording != null)
  706.                                 {
  707.                                     switch (scheduledRecording.getRecordingStatus())
  708.                                     {
  709.                                         case ScheduledRecording.STATUS_PENDING:
  710.                                             return "Pending";
  711.                                         case ScheduledRecording.STATUS_IN_PROGRESS:
  712.                                             return "In Progress";
  713.                                         case ScheduledRecording.STATUS_COMPLETED:
  714.                                             return "Available";
  715.                                         case ScheduledRecording.STATUS_COMPLETED_WITH_ERROR:
  716.                                             return "Failed";
  717.                                         case ScheduledRecording.STATUS_CONFLICT:
  718.                                             return "Conflict";
  719.                                         case ScheduledRecording.STATUS_PLACE_HOLDER:
  720.                                             return "Reoccurring";
  721.                                         case ScheduledRecording.STATUS_DELETED:
  722.                                             return "Deleted";
  723.                                         default:
  724.                                             return " ";
  725.                                     }
  726.                                 }
  727.                                 else
  728.                                 {
  729.                                     return " ";
  730.                                 }
  731.                             }
  732.                         case "datetime":
  733.                             {
  734.                                 scheduledRecording = null;
  735.                                 if (knownRecordings.Contains(pgm.getOID()))
  736.                                     scheduledRecording = (ScheduledRecording)knownRecordings[pgm.getOID()];
  737.                                 if (scheduledRecording != null)
  738.                                 {
  739.                                     switch (scheduledRecording.getRecordingType())
  740.                                     {
  741.                                         case ScheduledRecording.TYPE_RECORD_ONCE:
  742.                                             return scheduledRecording.getStartTime().Ticks;
  743.                                         default:
  744.                                             return scheduledRecording.getStartTime().TimeOfDay.Ticks;
  745.                                     }
  746.                                 }
  747.                                 else
  748.                                 {
  749.                                     return pgm.getStartTime().Ticks;
  750.                                 }
  751.                             }
  752.                         case "channel":
  753.                             {
  754.                                 if (pgm != null)
  755.                                 {
  756.                                     Channel channel = scheduleHelper.GetChannelByOID(pgm.getChannelOID());
  757.                                     if (channel != null)
  758.                                     {
  759.                                         return channel.getChannelNumber();
  760.                                     }
  761.                                 }
  762.                                 return 0;
  763.                             }
  764.                         case "title":
  765.                             {
  766.                                 scheduledRecording = null;
  767.                                 if (knownRecordings.Contains(pgm.getOID()))
  768.                                     scheduledRecording = (ScheduledRecording)knownRecordings[pgm.getOID()];
  769.                                 if (scheduledRecording != null)
  770.                                 {
  771.                                     switch (scheduledRecording.getRecordingType())
  772.                                     {
  773.                                         case ScheduledRecording.TYPE_RECORD_ONCE:
  774.                                             if (pgm.getSubTitle().Length > 0)
  775.                                             {
  776.                                                 return pgm.getTitle() + ": " + pgm.getSubTitle();
  777.                                             }
  778.                                             else
  779.                                             {
  780.                                                 return pgm.getTitle();
  781.                                             }
  782.                                         default:
  783.                                             return scheduledRecording.getFileName();
  784.                                     }
  785.                                 }
  786.                                 else
  787.                                 {
  788.                                     if (pgm.getSubTitle().Length > 0)
  789.                                     {
  790.                                         return pgm.getTitle() + ": " + pgm.getSubTitle();
  791.                                     }
  792.                                     else
  793.                                     {
  794.                                         return pgm.getTitle();
  795.                                     }
  796.                                 }
  797.                             }
  798.                         default:
  799.                             return string.Empty;
  800.                     }
  801.                 }
  802.                 else
  803.                 {
  804.                     switch (key)
  805.                     {
  806.                         case "status":
  807.                             {
  808.                                 switch (scheduledRecording.getRecordingStatus())
  809.                                 {
  810.                                     case ScheduledRecording.STATUS_PENDING:
  811.                                         return "Pending";
  812.                                     case ScheduledRecording.STATUS_IN_PROGRESS:
  813.                                         return "In Progress";
  814.                                     case ScheduledRecording.STATUS_COMPLETED:
  815.                                         return "Available";
  816.                                     case ScheduledRecording.STATUS_COMPLETED_WITH_ERROR:
  817.                                         return "Failed";
  818.                                     case ScheduledRecording.STATUS_CONFLICT:
  819.                                         return "Conflict";
  820.                                     case ScheduledRecording.STATUS_PLACE_HOLDER:
  821.                                         return "Reoccurring";
  822.                                     case ScheduledRecording.STATUS_DELETED:
  823.                                         return "Deleted";
  824.                                     default:
  825.                                         return "NONE!!";
  826.                                 }
  827.                             }
  828.                         case "datetime":
  829.                             {
  830.                                 switch (scheduledRecording.getRecordingType())
  831.                                 {
  832.                                     case ScheduledRecording.TYPE_RECORD_ONCE:
  833.                                         return scheduledRecording.getStartTime().Ticks;
  834.                                     default:
  835.                                         return scheduledRecording.getStartTime().TimeOfDay.Ticks;
  836.                                 }
  837.                             }
  838.                         case "channel":
  839.                             {
  840.                                 Channel channel = scheduleHelper.GetChannelByOID(pgm.getChannelOID());
  841.                                 if (channel != null)
  842.                                 {
  843.                                     return channel.getChannelNumber();
  844.                                 }
  845.                                 return 0;
  846.                             }
  847.                         case "title":
  848.                             {
  849.                                 Programme programme = scheduledRecording.getProgramme();
  850.                                 switch (scheduledRecording.getRecordingType())
  851.                                 {
  852.                                     case ScheduledRecording.TYPE_RECORD_ONCE:
  853.                                         if (programme == null)
  854.                                         {
  855.                                             return "Manual Recording";
  856.  
  857.                                         }
  858.                                         else
  859.                                         {
  860.                                             if (programme.getSubTitle().Length > 0)
  861.                                             {
  862.                                                 return programme.getTitle() + ": " + programme.getSubTitle();
  863.                                             }
  864.                                             else
  865.                                             {
  866.                                                 return programme.getTitle();
  867.                                             }
  868.                                         }
  869.                                     default:
  870.                                         return scheduledRecording.getFileName();
  871.                                 }
  872.                             }
  873.                         default:
  874.                             return string.Empty;
  875.                     }
  876.                 }
  877.  
  878.             }
  879.         }
  880.         #endregion
  881.  
  882.     }
  883. }
  884.